<template>
    <!-- pages/taskStatics/taskStatics.wxml -->
    <view class="container">
        <!-- 统计 -->
        <view class="section">
            <view class="title border-primary">
                <view class="bg-primary"></view>
                今日
            </view>
            <view class="box">
                <view class="item" @tap="golist" data-time="today" data-status="1">
                    <view>
                        <text>{{ info.todayJiedan }}</text>
                        单
                    </view>
                    <view class="blue2">已接单</view>
                </view>
                <view class="item" @tap="golist" data-time="today" data-status="2">
                    <view>
                        <text>{{ info.todayStart }}</text>
                        单
                    </view>
                    <view class="red">进行中</view>
                </view>
                <view class="item" @tap="golist" data-time="today" data-status="3">
                    <view>
                        <text>{{ info.todayFinish }}</text>
                        单
                    </view>
                    <view class="green">已完成</view>
                </view>
            </view>
        </view>
        <view class="section">
            <view class="title border-primary">
                <view class="bg-primary"></view>
                本月
            </view>
            <view class="box">
                <view class="item" @tap="golist" data-time="month" data-status="6">
                    <view>
                        <text>{{ info.tomonthJiesuan }}</text>
                        单
                    </view>
                    <view class="blue2">已结算</view>
                </view>
                <view class="item" @tap="golist" data-time="month" data-status="3">
                    <view>
                        <text>{{ info.tomonthFinish }}</text>
                        单
                    </view>
                    <view class="green">已完成</view>
                </view>
                <view class="item" @tap="golist" data-time="month" data-status="5">
                    <view>
                        <text>{{ info.tomonthBohui }}</text>
                        单
                    </view>
                    <view class="yellow">已驳回</view>
                </view>
            </view>
        </view>
        <view class="section">
            <view class="title border-primary">
                <view class="bg-primary"></view>
                总收入统计
            </view>
            <view class="box">
                <view class="item" @tap="golist" data-time="" data-status="3">
                    <view>
                        <text>{{ info.totalFinish }}</text>
                        单
                    </view>
                    <view class="green">已完成</view>
                </view>
                <view class="item" @tap="golist" data-time="" data-status="6">
                    <view>
                        <text>{{ info.totalSettlementt }}</text>
                        单
                    </view>
                    <view class="blue">已结算</view>
                </view>
                <view class="item">
                    <view>
                        <text>{{ info.totalMoney }}</text>
                        元
                    </view>
                    <view class="green">总收入</view>
                </view>
            </view>
        </view>
        <!-- 明细 -->
        <view class="list">
            <view class="title">
                <view class="border bg-primary"></view>
                结算记录
            </view>
            <block v-if="list.length">
                <view class="item" @tap="golist" data-time="" data-status="6" v-for="(item, index) in list" :key="index">
                    <view class="line">
                        <label>结算时间：</label>
                        {{ item.createTime }}
                    </view>

                    <view class="line">
                        <label>结算数量：</label>
                        {{ item.orderNum }}单
                    </view>

                    <view class="total color-primary">
                        <view class="price">+{{ item.money }}元</view>
                    </view>
                </view>
                <view class="noteMore">下拉查看更多...</view>
            </block>
            <block v-else><view class="nodata">暂无数据</view></block>
        </view>
    </view>
</template>

<script>
// pages/taskStatics/taskStatics.js
const app = getApp();
var http = require('../../../utils/http');
var util1 = require('../../../utils/util.js');
var Moment = require('../../../lib/moment.js');
export default {
    data() {
        return {
            info: {
                todayJiedan: '',
                todayStart: '',
                todayFinish: '',
                tomonthJiesuan: '',
                tomonthFinish: '',
                tomonthBohui: '',
                totalFinish: '',
                totalSettlementt: '',
                totalMoney: ''
            },
            pageNo: 1,
            pageSize: 10,
            canLoadMore: true,
            //是否还能加载更多
            list: []
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        this.getData();
        this.getMainListdata('refresh');
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
        let that = this;
        this.setData({
            pageNo: 1,
            canLoadMore: true,
            list: []
        });
        this.getMainListdata('refresh');
        uni.stopPullDownRefresh();
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        let that = this;
        if (that.canLoadMore) {
            that.pageNo++;
            this.getMainListdata('');
        } else {
            uni.showToast({
                title: '我是有底线的...'
            });
        }
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        // 获取详情
        getData: function () {
            let that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/clear/getChartData',
                    '1',
                    'get',
                    {},
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('返回111===');
                        console.info(info);
                        if (info.code == 0) {
                            that.setData({
                                info: info.data
                            });
                        } else {
                            uni.showModal({
                                content: info.msg,
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        //获取列表数据
        getMainListdata: function (e) {
            var that = this;
            let message = '';
            if (app.globalData.isLogin) {
                if (e == 'refresh') {
                    //刷新，page变为1
                    message = '正在加载';
                    that.setData({
                        pageNo: 1
                    });
                }
                http.request(
                    '/member/clear/getClearBillPage',
                    '1',
                    'post',
                    {
                        pageNo: that.pageNo,
                        pageSize: that.pageSize
                    },
                    app.globalData.userDatatoken.accessToken,
                    message,
                    function success(info) {
                        console.info('返回111===');
                        console.info(info);
                        if (info.code == 0) {
                            if (e == 'refresh') {
                                that.setData({
                                    list: info.data.list
                                });
                                if (info.data.list.length === 0) {
                                    that.setData({
                                        canLoadMore: false
                                    });
                                }
                            } else {
                                if (info.data != null && info.data.list.length <= info.data.total) {
                                    that.setData({
                                        canLoadMore: false
                                    });
                                }
                                let arr = that.list;
                                let arrs = arr.concat(info.data.list);
                                that.setData({
                                    list: arrs
                                });
                            }
                        } else {
                            uni.showModal({
                                content: '请求服务异常，请稍后重试',
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        golist: function (e) {
            var time = e.currentTarget.dataset.time;
            var status = e.currentTarget.dataset.status;
            var startTime = '';
            var endTime = '';
            if (time == 'today') {
                startTime = Moment().format('YYYY-MM-DD');
                endTime = Moment().format('YYYY-MM-DD');
            } else if (time == 'month') {
                startTime = Moment().startOf('months').format('YYYY-MM-DD');
                endTime = Moment().endOf('months').format('YYYY-MM-DD');
            }
            uni.navigateTo({
                url: '../task/task?status=' + status + '&startTime=' + startTime + '&endTime=' + endTime
            });
        }
    }
};
</script>
<style>
@import './taskStatics.css';
</style>
